﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jbe.TestSuite.Infrastructure.Interface;
using Jbe.TestSuite.TestDevices.FunctionGenerator.Interface;
using System.ComponentModel;
using Jbe.Composite.Extensions;
using System.Reflection;

namespace Jbe.TestSuite.TestDevices.FunctionGenerator.ControlView.Applications
{
    // INFO: This PresentationModel is responsible for data mapping to get it in a wpf data binding frindly form.
    internal class ConfigurationPresentationModel : PresentationModel<IConfigurationView>
    {
        private IFunctionGeneratorConfig config;


        public ConfigurationPresentationModel(IConfigurationView view)
            : base(view)
        {
        }


        public IFunctionGeneratorConfig Config
        {
            get { return config; }
            set
            {
                if (config != value)
                {
                    config = value;
                    RaisePropertyChanged("Config");
                    RaisePropertyChanged("SineWaveForm");
                    RaisePropertyChanged("SquareWaveForm");
                    RaisePropertyChanged("TriangleWaveForm");
                    RaisePropertyChanged("SawtoothWaveForm");
                }
            }
        }

        public bool SineWaveForm
        {
            get { return config.WaveForm == WaveForm.Sine; }
            set
            {
                if (config.WaveForm != WaveForm.Sine)
                {
                    config.WaveForm = WaveForm.Sine;
                    RaiseWaveFormChanged();
                }
            }
        }

        public bool SquareWaveForm
        {
            get { return config.WaveForm == WaveForm.Square; }
            set
            {
                if (config.WaveForm != WaveForm.Square)
                {
                    config.WaveForm = WaveForm.Square;
                    RaiseWaveFormChanged();
                }
            }
        }

        public bool TriangleWaveForm
        {
            get { return config.WaveForm == WaveForm.Triangle; }
            set
            {
                if (config.WaveForm != WaveForm.Triangle)
                {
                    config.WaveForm = WaveForm.Triangle;
                    RaiseWaveFormChanged();
                }
            }
        }

        public bool SawtoothWaveForm
        {
            get { return config.WaveForm == WaveForm.Sawtooth; }
            set
            {
                if (config.WaveForm != WaveForm.Sawtooth)
                {
                    config.WaveForm = WaveForm.Sawtooth;
                    RaiseWaveFormChanged();
                }
            }
        }


        private void RaiseWaveFormChanged()
        {
            RaisePropertyChanged("SineWaveForm");
            RaisePropertyChanged("SquareWaveForm");
            RaisePropertyChanged("TriangleWaveForm");
            RaisePropertyChanged("SawtoothWaveForm");
        }
    }
}
